package com.jason.www.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author：Jason
 * @date：2020/8/11 11:09
 * @email：1129847330@qq.com
 * @description:
 */
public class DateUtils {
    public static final String PATTERN_YMDHMS = "yyyy-MM-dd HH:mm:ss";
    private static SimpleDateFormat format_ymdhms = new SimpleDateFormat(PATTERN_YMDHMS);

    public static String formatTimeStamp2YMDHms(long timestamp) {
        return format_ymdhms.format(new Date(timestamp));
    }

    public static String getFormattedWeek(int day) {
        String mWay = String.valueOf(day);
        if ("1".equals(mWay)) {
            mWay = "周日";
        } else if ("2".equals(mWay)) {
            mWay = "周一";
        } else if ("3".equals(mWay)) {
            mWay = "周二";
        } else if ("4".equals(mWay)) {
            mWay = "周三";
        } else if ("5".equals(mWay)) {
            mWay = "周四";
        } else if ("6".equals(mWay)) {
            mWay = "周五";
        } else if ("7".equals(mWay)) {
            mWay = "周六";
        }
        return mWay;
    }

    /**
     * 获取前后一个月的时间
     *
     * @return
     */
    public static List<String[]> getBeforeBehindOneMonth() {
        ArrayList<String[]> list = new ArrayList();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, -30);
        for (int i = 0; i < 60; i++) {
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            int week = calendar.get(Calendar.DAY_OF_WEEK);
            int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
            String timeStamp = String.valueOf(calendar.getTimeInMillis());
            list.add(new String[]{Calendar.getInstance().get(Calendar.DAY_OF_YEAR) == dayOfYear ? "今天" : getFormattedWeek(week), String.valueOf(day), timeStamp});
            calendar.add(Calendar.DAY_OF_YEAR, 1);
        }
        return list;
    }
}